package gui.components.JXTable.JXCell;

import gui.components.JXTable.JXTableModel.JXTableModel;

import java.awt.*;
import java.util.ArrayList;

/**
 * User: Programmer
 * Date: 08.05.2006
 * Time: 10:28:44
 */
public class JXCell implements iJXCell{
    //private JXCellRenderer renderer = null;
    private JXTableModel dtm = null;
    private int column = 0;
    private int row = 0;
    private ArrayList<iJXCellRenderer> renderers = new ArrayList<iJXCellRenderer>();

    public JXCell(ArrayList<iJXCellRenderer> renderers, JXTableModel dtm, int row, int column){
        this.renderers = renderers;
        this.column = column;
        this.row = row;
        this.dtm = dtm;
    }

    public void setColor(Color color){
        for(int i=0;i<renderers.size();i++)
        renderers.get(i).addColorCell(row,column,color);
    }

    public void setEditable(boolean bool){
        if(bool){dtm.addNotEditableCell(row,column);}
        else{dtm.removeNotEditableCell(row,column);}
    }

    public Object getValue(){
        return dtm.getValueAt(row,column);
    }

    public String getValueAsString(){
        if(column==0)return null;
        Object ob = dtm.getValueAt(row,column);
        return (ob!=null)?ob.toString():null;
    }

    public void setValue(int row, int column, Object ob){
        if(column==0)return;
        dtm.setValueAt(ob,row,column);
    }
    public void setValue(Object ob){
        if(column==0)return;
        dtm.setValueAt(ob,row,column);
    }
}
